<?php

	/**
	 * Restaurant Item
	 *
	 * @author anton.perkin
	 * @version 1.0
	 *
	 */
	class RestaurantItem
	{
		/* VARIABLES */
		
		public $id;
		public $name;
		public $cuisine;
		public $addressLine1;
		public $addressLine2;
		public $city;
		public $state;
		public $zip;
		public $country;
		public $phone;
		public $email;
		public $webAddress;
		public $pricePoint;
		public $photoURL;
		public $source;
		public $urlId;
		
		
		/* METHODS */
		
		/**
		 * Saves RestaurantItem into database
		 *
		 */
		public function Save()
		{
			if (DB::ExecuteSQL("
				INSERT INTO t_restaurants
				(
					product_id,
					name,
					cuisine,
					address_line1,
					address_line2,
					city,
					state,
					zip,
					country,
					phone,
					email,
					web_address,
					price_point,
					source,
					url_id
				)
				VALUES
				(
					$this->id,
					'".addslashes($this->name)."',
					'".addslashes($this->cuisine)."',
					'".addslashes($this->addressLine1)."',
					'".addslashes($this->addressLine2)."',
					'".addslashes($this->city)."',
					'".addslashes($this->state)."',
					'".addslashes($this->zip)."',
					'".addslashes($this->country)."',
					'".addslashes($this->phone)."',
					'".addslashes($this->email)."',
					'$this->webAddress',
					'".addslashes($this->pricePoint)."',
					'$this->source',
					$this->urlId
				);
			") === true)
			{
				$this->Log(true);
				$result = true;
			}	
			else 
			{
				$this->Log(false);
				$result = false;
			}	
//echo "
//				INSERT INTO t_restaurants
//				(
//					product_id,
//					name,
//					cuisine,
//					address_line1,
//					address_line2,
//					city,
//					state,
//					zip,
//					country,
//					phone,
//					email,
//					web_address,
//					price_point,
//					source,
//					url_id
//				)
//				VALUES
//				(
//					$this->id,
//					'".addslashes($this->name)."',
//					'".addslashes($this->cuisine)."',
//					'".addslashes($this->addressLine1)."',
//					'".addslashes($this->addressLine2)."',
//					'".addslashes($this->city)."',
//					'".addslashes($this->state)."',
//					'".addslashes($this->zip)."',
//					'".addslashes($this->country)."',
//					'".addslashes($this->phone)."',
//					'".addslashes($this->email)."',
//					'$this->webAddress',
//					'".addslashes($this->pricePoint)."',
//					'$this->source',
//					$this->urlId
//				);
//			";
			return $result;
		}
		
		/**
		 * Saves restaurant URL into database
		 *
		 * @param string $url url
		 * @param string $source source
		 * 
		 * @return boolean
		 * 
		 */
		public function SaveURL($url, $source)
		{
			if (DB::ExecuteSQL("
				INSERT INTO t_restaurant_urls
				(
					url,
					source
				)
				VALUES
				(
					'$url',
					'$source'
				);
					
			") === true)
			{
				$this->LogURL($url, $source, true);
				$result = true;
			}	
			else 
			{
				$this->LogURL($url, $source, false);
				$result = false;
			}	

			return $result;
		}
		
		/**
		 * Creates log entry for the inserted restaurant
		 * 
		 * @param boolean $success result
		 *
		 */
		private function Log($success)
		{
			$color = ($success) ? 'green' : 'red';

			echo "<span style = 'color: $color; '>Id: $this->id | urlId: $this->urlId</span><br />";
			
//			echo "<span style = 'color: $color; '>
//			----------------------------------------------------------------------------------------------------------------<br />
//			Id: $this->id | Name: $this->name | DisplayName: $this->displayName | Vintage: $this->vintage | Region: $this->region | 
//			SubRegion: $this->subRegion | Grape: $this->grape | Varietal: $this->varietal | Appelation: $this->appelation | 
//			Producer: $this->producer | WebAddress: $this->webAddress | Type: $this->type | PhotoURL: $this->photoURL <br />
//			----------------------------------------------------------------------------------------------------------------</span><br />";
		}

		/**
		 * Creates log entry for the inserted restaurant URL
		 *
		 * @param string $url url
		 * @param string $source source
		 * @param boolean $success result
		 */
		private function LogURL($url, $source, $success)
		{
			$color = ($success) ? 'green' : 'red';
			
			echo "<span style = 'color: $color; '>
			URL: $url | Source: $source
			</span><br />";
		}
		
	}

?>